package org.example.mapper;

import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.example.pojo.ExpireGoodsVo;
import org.example.pojo.Goods;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface GoodsMapper {
    /**
     * 分页查询商品
     * @param categoryId
     * @param goodsName
     * @param vendorId
     * @return
     */
    Page<Goods> list(Integer categoryId, String goodsName,Integer vendorId);

    /**
     * 添加商品
     * @param goods
     */
    void add(Goods goods);

    /**
     * 修改商品
     * @param goods
     */
    void update(Goods goods);

    /**
     * 删除商品
     * @param id
     */
    @Delete("delete from goods where id = #{id}")
    void delete(Integer id);

    /**
     * 根据分类id查询商品
     * @param id
     * @return
     */
    @Select("select * from goods where category_id = #{id}")
    List<Goods> listByCategoryId(Integer id);

    /**
     * 根据供应商id查询商品
     * @param id
     * @return
     */
    @Select("select * from goods where vendor_id = #{id}")
    List<Goods> listByVendorId(Integer id);

    /**
     * 分页查询商品2
     * @param categoryId
     * @param goodsName
     * @param vendorId
     * @return
     */
    Page<Goods> list2(Integer categoryId, String goodsName, Integer vendorId, int inventory);

    /**
     * 查询所有商品
     * @return
     */
    @Select("select * from goods")
    List<Goods> list3();

    /**
     * 查询库存前10个商品
     * @return
     */
    @Select("select goods.*,inventory.quantity from goods left join inventory on goods.id = inventory.goods_id order by quantity desc limit 10")
    List<Goods> getTop10Name();

    /**
     * 查询所有商品 根据时间范围
     * @return
     */
    @Select("select * from goods where create_time between #{start} and #{end}")
    List<Goods> getAllGoods(LocalDateTime start,LocalDateTime end);

    /**
     * 根据商品名称查询商品
     * @param goods
     * @return
     */
    @Select("select * from goods where goods_name = #{goodsName}")
    Goods getByName(Goods goods);

    /**
     * 分页查询过期商品
     * @param goodsName
     * @param category
     * @return
     */
    Page<ExpireGoodsVo> expireList(String goodsName, Integer category);

    /**
     * 查询所有商品
     * @return
     */
    @Select("select * from goods")
    List<Goods> getGoodsList();
}
